package com.mtl.front.service.impl;

import com.github.pagehelper.PageHelper;
import com.mtl.common.tool.model.Page;
import com.mtl.front.domain.Sort;
import com.mtl.front.mapper.TSortMapper;
import com.mtl.front.service.ISortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 文章分类 服务实现类
 *
 * @author qms
 * @since 2019-08-06
 */
@Service
public class TSortServiceImpl implements ISortService {

    @Autowired
    private TSortMapper sortMapper;

    @Override
    public Sort findById(Integer id) {
        return sortMapper.selectByPrimaryKey(id);
    }

    @Override
    public Page<Sort> findPage(Integer page, Integer size,String search) {
        PageHelper.startPage(page,size);
        List<Sort> sort=sortMapper.selectByCondition(search);
        return new Page<>(sort);
    }

    @Override
    public int saveOrUpdate(Sort sort) {
        if(sort.getSortId()!=null){
        return sortMapper.updateByPrimaryKey(sort);
        }
        return sortMapper.insert(sort);
    }

    @Override
    public int deleteBatch(List<Integer> ids) {
        return sortMapper.deleteByIdList(ids);
    }

    @Override
    public List<Sort> findAll() {
        return sortMapper.selectAll();
    }
}
